package com.tojabo.swing.six_pane;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class JTabbedPaneDemo2 extends JTabbedPane {

	static final int WIDTH = 600;
	static final int HEIGHT = 350;

	JTabbedPaneDemo2() {
		
		
		
		JFrame frame = new JFrame();
		
		frame.setTitle("面板综合测试窗口");
		frame.setSize(WIDTH, HEIGHT);
		frame.setVisible(true);
		frame.setContentPane(this);
		
		try {// 显示外观风格
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			System.out.println("UIManager==>"+UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int width = screenSize.width;
		int height = screenSize.height;
		int x = (width - WIDTH) / 2;
		int y = (height - HEIGHT) / 2;
		frame.setLocation(x, y);

		studentinfo info = new studentinfo();
		addTab("info", info);
		setEnabledAt(0, true);
		setTitleAt(0, "基本信息");
		
		studentinfo1 info1 = new studentinfo1();
		addTab("info1", info1);
		setEnabledAt(1, true);
		setTitleAt(1, "我的信息");
		
		//frame.pack();
	}

	public static void main(String[] args) {
		new JTabbedPaneDemo2();
	}

}

class studentinfo extends JPanel {
	public void add(Component c, GridBagConstraints constraints, int x, int y,
			int w, int h) {
		constraints.gridx = x;
		constraints.gridy = y;
		constraints.gridwidth = w;
		constraints.gridheight = h;
		add(c, constraints);
	}

	studentinfo() {
		JLabel name = new JLabel("姓名");
		JLabel sexy = new JLabel("性别");
		JLabel age = new JLabel("年龄");
		JLabel birthday = new JLabel("出生年月");
		JLabel address = new JLabel("家庭地址");
		JTextField nameinput = new JTextField(10);
		JTextField sexyinput = new JTextField(10);
		JTextField ageinput = new JTextField(10);
		JTextField birthdayinput = new JTextField(10);
		JTextField addressinput = new JTextField(10);
		GridBagLayout lay = new GridBagLayout();
		setLayout(lay);
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.NONE;
		constraints.weightx = 2;
		constraints.weighty = 5;
		add(name, constraints, 0, 0, 1, 1);
		add(nameinput, constraints, 1, 0, 1, 1);
		add(sexy, constraints, 0, 1, 1, 1);
		add(sexyinput, constraints, 1, 1, 1, 1);
		add(age, constraints, 0, 2, 1, 1);
		add(ageinput, constraints, 1, 2, 1, 1);
		add(birthday, constraints, 0, 3, 1, 1);
		add(birthdayinput, constraints, 1, 3, 1, 1);
		add(address, constraints, 0, 4, 1, 1);
		add(addressinput, constraints, 1, 4, 1, 1);
	}
}
class studentinfo1 extends JPanel {
	public void add(Component c, GridBagConstraints constraints, int x, int y,
			int w, int h) {
		constraints.gridx = x;
		constraints.gridy = y;
		constraints.gridwidth = w;
		constraints.gridheight = h;
		add(c, constraints);
	}

	studentinfo1() {
		JLabel name = new JLabel("name");
		JLabel sexy = new JLabel("sex");
		JLabel age = new JLabel("age");
		JLabel birthday = new JLabel("bothday");
		JLabel address = new JLabel("address");
		JTextField nameinput = new JTextField(10);
		JTextField sexyinput = new JTextField(10);
		JTextField ageinput = new JTextField(10);
		JTextField birthdayinput = new JTextField(10);
		JTextField addressinput = new JTextField(10);
		GridBagLayout lay = new GridBagLayout();
		setLayout(lay);
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.NONE;
		constraints.weightx = 2;
		constraints.weighty = 5;
		add(name, constraints, 0, 0, 1, 1);
		add(nameinput, constraints, 1, 0, 1, 1);
		add(sexy, constraints, 0, 1, 1, 1);
		add(sexyinput, constraints, 1, 1, 1, 1);
		add(age, constraints, 0, 2, 1, 1);
		add(ageinput, constraints, 1, 2, 1, 1);
		add(birthday, constraints, 0, 3, 1, 1);
		add(birthdayinput, constraints, 1, 3, 1, 1);
		add(address, constraints, 0, 4, 1, 1);
		add(addressinput, constraints, 1, 4, 1, 1);
	}
}